<template>
  <div class="cc-main-menu">
    <q-item-section side>
      <q-badge color="red">{{ menu.num}}</q-badge>
    </q-item-section>
  </div>
</template>

<script>
export default {
  props: {
    menu: Object,
  },
  components: {},
  data() {
    return {
      num: null
    };
  },
  watch: {},
  computed: {
  },
  methods: {
    getCount() {
      if (this.menu.statUrl) {
        this.$axios.get(this.menu.statUrl).then((result) => {
          this.num = result.result;
        });
      }
    },
  },
  created() {
  },
  mounted() {
    if (this.menu.statUrl) {
      this.$root.$on(this.menu.id, this.getCount);
    }
    this.getCount();
  },
  destory() {
    if (this.menu.statUrl) {
      this.$root.$off(this.menu.id, this.getCount);
    }
  },
  beforeDestroy() {
    this.$root.$off(this.menu.id);
  },
};
</script>
